<template>
	<view class="reprot ff-padding-bottom-70">
		<view class="report-header ff-bg-blue">
			<view class="report-header-content ff-align-items-one ff-flex-between">
				<view class="report-header-content-success ff-color-fff ff-font-18">
					已完成 第
					<text class="ff-font-28 ff-padding-left-5 ff-padding-right-6">{{ reportInfo.mainNum }}</text>
					次维保
				</view>
				<view v-if="reportInfo.scoreEvaluate == '' || reportInfo.scoreEvaluate == null">
					<image @click="evaluationClick(reportInfo.id)"
						src="https://fire-system.oss-cn-beijing.aliyuncs.com/web/fire-technology/report-evaluate.png"
						mode=""></image>
				</view>
			</view>
		</view>
		<view class="report-content ff-border-radius-10 ff-bg-fff ff-margin-12 ff-font-14">
			<view class="report-content-info-header ff-padding-left-15 ff-padding-right-15 ff-padding-top-15">
				<view class="ff-font-16 ff-font-weight-600 ff-color-000">{{ reportInfo.projectName }}</view>
				<view class="ff-align-items-one ff-flex-wrap">
					<view class="ff-margin-right-10">
						<view v-if="reportInfo.projectStatus == 0" class="tips1 ff-font-12">项目状态&nbsp;|&nbsp;已发布</view>
						<view v-if="reportInfo.projectStatus == 1" class="tips1 ff-font-12">项目状态&nbsp;|&nbsp;已响应</view>
						<view v-if="reportInfo.projectStatus == 2" class="tips1 ff-font-12">项目状态&nbsp;|&nbsp;已确认</view>
						<view v-if="reportInfo.projectStatus == 3" class="tips1 ff-font-12">项目状态&nbsp;|&nbsp;进行中</view>
						<view v-if="reportInfo.projectStatus == 4" class="tips1 ff-font-12">项目状态&nbsp;|&nbsp;已结束</view>
						<view v-if="reportInfo.projectStatus == 5" class="tips1 ff-font-12">项目状态&nbsp;|&nbsp;待批准</view>
						<view v-if="reportInfo.projectStatus == 6" class="tips5 ff-font-12">项目状态&nbsp;|&nbsp;已解约</view>
						<view v-if="reportInfo.projectStatus == 9" class="tips5 ff-font-12">项目状态&nbsp;|&nbsp;已作废</view>
					</view>
					<view class="ff-margin-right-10">
						<view v-if="reportInfo.status == 0" class="tips2 ff-font-12">维保状态&nbsp;|&nbsp;待维保</view>
						<view v-if="reportInfo.status == 1" class="tips2 ff-font-12">维保状态&nbsp;|&nbsp;维保中</view>
						<view v-if="reportInfo.status == 2" class="tips2 ff-font-12">维保状态&nbsp;|&nbsp;待审核</view>
						<view v-if="reportInfo.status == 3" class="tips2 ff-font-12">维保状态&nbsp;|&nbsp;待签发</view>
						<view v-if="reportInfo.status == 5" class="tips2 ff-font-12">维保状态&nbsp;|&nbsp;已完成</view>
						<view v-if="reportInfo.status == 6" class="tips2 ff-font-12">维保状态&nbsp;|&nbsp;已驳回</view>
						<view v-if="reportInfo.status == 7" class="tips2 ff-font-12">维保状态&nbsp;|&nbsp;待指派</view>
						<view v-if="reportInfo.status == 8" class="tips2 ff-font-12">维保状态&nbsp;|&nbsp;待提交</view>
						<view v-if="reportInfo.status == 9" class="tips5 ff-font-12">维保状态&nbsp;|&nbsp;已作废</view>
					</view>
				</view>
				<view class="ff-font-13 ff-color-5C5F65 ff-margin-top-10">
					<u-icon name="map"></u-icon>
					{{ reportInfo.projectAddr }}
				</view>
				<image src="https://fire-system.oss-cn-beijing.aliyuncs.com/web/fire-technology/report-edit.png"
					mode=""></image>
			</view>
			<view class="report-content-info-box ff-padding-10"
				v-if="reportInfo.status == 5 && reportInfo.scoreEvaluate">
				<view
					class="report-content-info-box-title ff-font-16 ff-font-weight-600 ff-color-5C5F65 ff-border-radius-5">
					社会单位对本次服务的点评</view>
				<view class="report-content-info-box-content">
					<view class="ff-text-center report-content-info-box-content-result">
						<u-rate :disabled="true" v-model="reportInfo.scoreEvaluate" active-color="#FF6633" size="45"
							inactive-color="#ECECEC" gutter="20"></u-rate>
						<view class="report-content-info-box-content-result-text">
							<u-input :disabled="true" height="190" border="true" v-model="reportInfo.evaluateContent"
								type="textarea" maxlength="-1" />
						</view>
					</view>
				</view>
			</view>
			<view class="report-content-info-box ff-padding-10">
				<view
					class="report-content-info-box-title ff-font-16 ff-font-weight-600 ff-color-5C5F65 ff-border-radius-5">
					项目概况</view>
				<view class="report-content-info-box-content ff-font-15">
					<view v-if="reportInfo.projectUniqueCode"
						class="ff-align-items-one ff-padding-left-5 ff-margin-bottom-16">
						<view class="report-content-info-box-content-left">项目ID</view>
						<view class="report-content-info-box-content-right">
							{{ reportInfo.projectUniqueCode }}
						</view>
					</view>
					<view class="ff-align-items-one ff-padding-left-5 ff-line-height-1-3 ff-margin-bottom-16">
						<view class="report-content-info-box-content-left">社会单位</view>
						<view class="ff-color-222 report-content-info-box-content-right">{{ reportInfo.companyName }}
						</view>
					</view>
					<view>
						<view v-if="reportInfo.mainBuilding.buildingNewTypeTopidName">
							<view class="ff-align-items-one ff-padding-left-5 ff-line-height-1-3 ff-margin-bottom-16">
								<view class="report-content-info-box-content-left">建筑类型</view>
								<view class="ff-color-222 report-content-info-box-content-right">
									{{ reportInfo.mainBuilding.buildingNewTypeTopidName }}
								</view>
							</view>
							<view class="ff-align-items-one ff-padding-left-5 ff-line-height-1-3 ff-margin-bottom-16">
								<view class="report-content-info-box-content-left">建筑物用途</view>
								<view class="ff-color-222 report-content-info-box-content-right">
									{{ reportInfo.mainBuilding.buildingNewTypeName || '--' }}
								</view>
							</view>
						</view>
						<view class="ff-align-items-one ff-padding-left-5 ff-line-height-1-3 ff-margin-bottom-16"
							v-else>
							<view class="report-content-info-box-content-left">场所类别</view>
							<view class="ff-color-222 report-content-info-box-content-right">
								{{ reportInfo.mainBuilding.buildingTypeName }}
							</view>
						</view>
					</view>
					<view
						class="ff-align-items-one ff-padding-left-5 ff-line-height-1-3 ff-line-height-1-3 ff-margin-bottom-16">
						<view class="report-content-info-box-content-left">高度(米)</view>
						<view class="ff-color-222 report-content-info-box-content-right">
							{{ reportInfo.mainBuilding.buildingHeight }}
						</view>
					</view>
					<view
						class="ff-align-items-one ff-padding-left-5 ff-line-height-1-3 ff-line-height-1-3 ff-margin-bottom-16">
						<view class="report-content-info-box-content-left">地上层数(层)</view>
						<view class="ff-color-222 report-content-info-box-content-right">
							{{ reportInfo.mainBuilding.buildingUpLayers }}
						</view>
					</view>
					<view
						class="ff-align-items-one ff-padding-left-5 ff-line-height-1-3 ff-line-height-1-3 ff-margin-bottom-16">
						<view class="report-content-info-box-content-left">地下层数(层)</view>
						<view class="ff-color-222 report-content-info-box-content-right">
							{{ reportInfo.mainBuilding.buildingDownLayers }}
						</view>
					</view>
					<view class="ff-align-items-one ff-padding-left-5 ff-line-height-1-3 ff-line-height-1-3">
						<view class="report-content-info-box-content-left">面积(m²)</view>
						<view class="ff-color-222 report-content-info-box-content-right">
							{{ reportInfo.mainBuilding.buildingArea }}
						</view>
					</view>
				</view>
			</view>
			<view class="report-content-info-box ff-padding-10">
				<view
					class="report-content-info-box-title ff-font-16 ff-font-weight-600 ff-color-5C5F65 ff-border-radius-5">
					维保人员</view>
				<view class="report-content-info-box-content">
					<view class="ff-flex ff-padding-left-5 ff-margin-bottom-16">
						<view class="report-content-info-box-content-left">指派人</view>
						<view class="report-content-info-box-content-right">
							{{ reportInfo.firstAssignmentName || '/' }}&nbsp;{{ reportInfo.firstAssignmentPhone||'' }}
						</view>
						<zb-tooltip placement="left" ref="tooltip13" color="white">
							<view slot="content">
								<view>
									首次指派人：{{ reportInfo.firstAssignmentName || '/' }}&nbsp;{{ reportInfo.firstAssignmentPhone || '' }}
								</view>
								<view v-if="reportInfo.firstAssignmentName != reportInfo.assignName">
									最新指派人：{{ reportInfo.assignName || '/' }}&nbsp;{{ reportInfo.assignPhone || '' }}
								</view>
							</view>
							<u-icon size="28" name="info-circle-fill" color="#3178FF"></u-icon>
						</zb-tooltip>
					</view>
					<view class="ff-flex ff-padding-left-5 ff-margin-bottom-16">
						<view class="report-content-info-box-content-left">指派时间</view>
						<view class="report-content-info-box-content-right">{{ reportInfo.firstAssignmentTime || '/' }}
						</view>
						<zb-tooltip placement="left" ref="tooltip13" color="white">
							<view slot="content">
								<view>首次指派时间：{{ reportInfo.firstAssignmentTime || '/' }}</view>
								<view v-if="reportInfo.firstAssignmentTime != reportInfo.assignTime">
									最新指派时间：{{ reportInfo.assignTime || '/' }}</view>
							</view>
							<u-icon size="28" name="info-circle-fill" color="#3178FF"></u-icon>
						</zb-tooltip>
					</view>
					<view class="ff-flex ff-padding-left-5 ff-margin-bottom-16">
						<view class="report-content-info-box-content-left">维护保养周期</view>
						<view class="report-content-info-box-content-right" v-if="reportInfo.maintenanceType == 1">月维保
						</view>
						<view class="report-content-info-box-content-right" v-if="reportInfo.maintenanceType == 2">季维保
						</view>
						<view class="report-content-info-box-content-right" v-if="reportInfo.maintenanceType == 3">半年维保
						</view>
						<view class="report-content-info-box-content-right" v-if="reportInfo.maintenanceType == 4">年度维保
						</view>
						<view class="report-content-info-box-content-right" v-if="reportInfo.maintenanceType == 5">特殊维保
						</view>
					</view>
					<view class="ff-flex ff-padding-left-5 ff-margin-bottom-16">
						<view class="report-content-info-box-content-left">技术负责人</view>
						<view class="report-content-info-box-content-right" v-if="reportInfo.signers">
							<view v-if="reportInfo.signers.length > 0">
								<view v-for="(item, index) of reportInfo.signers" :key="index">
									{{ item.username }}&nbsp;{{ item.phone }}
								</view>
							</view>
							<view v-else>/</view>
						</view>
					</view>
					<view class="ff-flex ff-padding-left-5 ff-margin-bottom-16">
						<view class="report-content-info-box-content-left">项目负责人</view>
						<view class="report-content-info-box-content-right">
							<view v-for="(item, index) of reportInfo.leaders" :key="index">
								{{ item.username }}&nbsp;{{ item.phone }}
							</view>
						</view>
					</view>
					<view class="ff-flex ff-padding-left-5 ff-margin-bottom-16">
						<view class="report-content-info-box-content-left">执业人员</view>
						<view class="report-content-info-box-content-right">
							<view v-for="(item, index) of reportInfo.operators" :key="index">
								{{ item.username }}&nbsp;{{ item.phone }}
							</view>
						</view>
					</view>
					<view class="ff-flex ff-padding-left-5 ff-margin-bottom-16">
						<view class="report-content-info-box-content-left">开始维保时间</view>
						<view class="report-content-info-box-content-right">{{ reportInfo.startTime || '/' }}</view>
					</view>
					<view class="ff-flex ff-padding-left-5">
						<view class="report-content-info-box-content-left">结束维保时间</view>
						<view class="report-content-info-box-content-right">{{ reportInfo.endTime || '/' }}</view>
					</view>
					<view v-if="reportInfo.cancelReason" class="ff-margin-top-16">
						<view class="ff-flex ff-padding-left-5 ff-margin-bottom-16">
							<view class="report-content-info-box-content-left">作废人</view>
							<view class="report-content-info-box-content-right">{{ reportInfo.cancelUserName || '/' }}
							</view>
						</view>
						<view class="ff-flex ff-padding-left-5 ff-margin-bottom-16">
							<view class="report-content-info-box-content-left">作废时间</view>
							<view class="report-content-info-box-content-right">{{ reportInfo.cancelTime || '/' }}
							</view>
						</view>
						<view class="ff-flex ff-padding-left-5">
							<view class="report-content-info-box-content-left">作废原因</view>
							<view class="report-content-info-box-content-right">{{ reportInfo.cancelReason || '/' }}
							</view>
						</view>
					</view>
				</view>
				<view class="report-content-info-box ff-padding-10">
					<view
						class="report-content-info-box-title ff-font-16 ff-font-weight-600 ff-color-5C5F65 ff-border-radius-5">
						维保概况</view>
					<view class="report-content-info-box-content">
						<view class="ff-padding-left-5 ff-line-height-1-5 ff-margin-bottom-16">
							<view class="ff-margin-bottom-5 report-content-info-box-content-textareaLeft ">
								本次维护保养情况简述及结论：
							</view>
							<!-- <view class="ff-color-222">{{ reportInfo.reportContent }}</view> -->
							<textarea :class="{textareaHeight:autoHeight}" maxlength="-1" :disabled="true"
								:value="reportInfo.reportContent" :auto-height="autoHeight"></textarea>
						</view>
						<view class="ff-padding-left-5 ff-line-height-1-5">
							<view class="ff-margin-bottom-5 report-content-info-box-content-textareaLeft ">已上报管理方待维修问题：
							</view>
							<!-- <view class="ff-color-222">{{ reportInfo.reportRepaired }}</view> -->
							<textarea :class="{textareaHeight:autoHeight}" maxlength="-1" :disabled="true"
								:value="reportInfo.reportRepaired" :auto-height="autoHeight"></textarea>
						</view>
					</view>
				</view>
				<view class="report-content-info-box ff-padding-10">
					<view
						class="report-content-info-box-title ff-font-16 ff-font-weight-600 ff-color-5C5F65 ff-border-radius-5">
						现场维保情况</view>
					<view class="report-content-info-box-content">
						<view @click="fireFacilitiesClick(item.id)"
							v-for="(item, ind) of reportInfo.mainBuilding.mainBuildingFacilities" :key="ind"
							class="ff-padding-left-5 report-content-info-box-content-fireList ff-padding-top-15 ff-padding-bottom-15 ff-align-items-one ff-flex-between">
							<view class="ff-font-15 ff-color-222">{{ ind + 1 }}.&nbsp;{{ item.facilitiesTypeName }}
							</view>
							<view><u-icon name="arrow-right" color="#3178FF" size="32"></u-icon></view>
						</view>
					</view>
				</view>
				<view class="report-content-info-box ff-padding-10">
					<view
						class="report-content-info-box-title ff-font-16 ff-font-weight-600 ff-color-5C5F65 ff-border-radius-5">
						附件：测试打印条</view>
					<view>
						<view v-if="reportInfo.testAttachs.length > 0">
							<u-row gutter="20">
								<u-col span="3" v-for="(item, index) of reportInfo.testAttachs" :key="index">
									<view class="report-content-info-box-content-img ff-margin-bottom-10"
										@click="previewClick(item)">
										<image :src="item" mode="" />
									</view>
								</u-col>
							</u-row>
						</view>
						<view v-else class="ff-color-999 ff-padding-left-5 ff-padding-bottom-30">暂无图片</view>
					</view>
				</view>
			</view>
			<!-- 按钮区 -->
			<cover-view class="report-but">
				<cover-view class="butPrimary" @click.stop="downloadReport">下载报告书</cover-view>
			</cover-view>
			<!-- 组件区 -->
			<u-back-top :scrollTop="scrollTopList.scrollTop" top="200" mode="circle"
				:iconStyle="scrollTopList.iconStyle" :customStyle="scrollTopList.customstyle"></u-back-top>
			<u-toast ref="uToast" />
			<f-loading ref="loading" />
		</view>

	</view>
</template>

<script>
	export default {
		name: 'Report',
		data() {
			return {
				autoHeight: false, // textarea高度
				// 返回顶部组件参数
				scrollTopList: {
					scrollTop: 0,
					iconStyle: {
						fontSize: '32rpx',
						color: '#FFFFFF'
					},
					customstyle: {
						background: '#3B83FE'
					}
				},
				reportInfo: [] // 报告书内容数据
			};
		},
		onPageScroll(e) {
			this.scrollTopList.scrollTop = e.scrollTop;
		},
		onLoad(e) {
			this.getTelInfo() // 获取机型
			this.getReportInfo(e.id); // 获取报告书详情数据
		},
		methods: {
			// 获取当前手机信息
			getTelInfo() {
				let that = this
				uni.getSystemInfo({
					success: function(res) {
						// console.log('当前机型信息', res.deviceBrand)
						if (res.deviceBrand == 'vivo') {
							that.autoHeight = false
						} else {
							that.autoHeight = true
						}
					}
				});
			},
			// 获取报告书详情数据
			async getReportInfo(maintenanceId) {
				this.$refs.loading.openLoading('加载中···');
				const data = await this.$http.post({
					url: `/maintenance/detailV3/${maintenanceId}`
				});
				// console.log('获取报告书详情数据-----', data);
				if (data.code == 200) {
					this.reportInfo = data.data;
					if (this.reportInfo.evaluateContent == null || this.reportInfo.evaluateContent == '') {
						this.reportInfo.evaluateContent = '暂无评价';
					}
					if (!this.reportInfo.reportContent) {
						this.reportInfo.reportContent = '暂无结论';
					}
					if (!this.reportInfo.reportRepaired) {
						this.reportInfo.reportRepaired = '暂无维修问题';
					}
				}
				this.$refs.loading.closeLoading();
			},
			// 评价服务
			evaluationClick(id) {
				this.$pageJump.navigateTo(
					'/pages/maintenance/company/home/components/details/components/evaluationServices?id=' + id);
			},
			// 点击跳转消防设施列表页面
			fireFacilitiesClick(id) {
				this.$pageJump.navigateTo(
					'/pages/maintenance/company/home/components/details/components/fireFacilities?id=' + id);
			},
			// 预览测试打印条的照片
			previewClick(img) {
				uni.previewImage({
					urls: this.reportInfo.testAttachs,
					current: img
				});
			},
			// 下载报告书
			downloadReport() {
				let that = this
				if (uni.getSystemInfoSync().platform == 'windows' || uni.getSystemInfoSync()
					.platform == 'mac' || uni.getSystemInfoSync().platform == 'linux') {
					uni.showModal({
						title: '警告',
						content: '小程序仅支持手机端操作',
						showCancel: false, // 是否显示取消按钮，默认为 true
						confirmColor: '#3178FF',
						success: res => {
							if (res.confirm) {}
						}
					});
					return
				}
				if (!that.reportInfo.reportUrl) {
					that.$refs.uToast.show({
						title: '报告书生成中，请稍后再试',
						type: 'warning'
					});
					return;
				}
				that.$refs.loading.openLoading('报告书获取中···');
				uni.downloadFile({
					url: this.reportInfo.reportUrl,
					success: function(res) {
						var filePath = res.tempFilePath;
						uni.openDocument({
							filePath: filePath,
							showMenu: true,
							success: function(res) {
								that.$refs.loading.closeLoading();
								// console.log('打开文档成功');
							}
						});
					}
				});
			}
		},
		onShareAppMessage() {
			return {
				title: '分享小程序给朋友',
				path: '/pages/homePage/Home'
			};
		}
	};
</script>

<style lang="scss" scoped>
	.report {
		&-header {
			height: 350rpx;

			&-content {
				position: relative;

				&-success {
					padding: 50rpx 56rpx;
				}

				image {
					width: 340rpx;
					height: 80rpx;
					position: absolute;
					right: 2%;
					top: 18%;
				}
			}
		}

		&-content {
			.tips1 {
				border: 2rpx solid #2b68ff;
				color: #2b68ff;
				padding: 10rpx 15rpx;
				border-radius: 8rpx;
				margin-top: 15rpx;
			}

			.tips2 {
				border: 2rpx solid #f0403d;
				color: #f0403d;
				padding: 10rpx 15rpx;
				border-radius: 8rpx;
				margin-top: 15rpx;
			}

			margin-top: -190rpx;
			position: relative;

			&-info {
				&-header {
					image {
						width: 230rpx;
						height: 230rpx;
						position: absolute;
						right: 0%;
						top: 0%;
					}
				}

				&-box {
					&-title {
						background: linear-gradient(to right, #eeeeee, #ffffff);
						padding: 24rpx 20rpx 20rpx;
						margin: 24rpx 0 28rpx;
					}

					&-content {
						&-left {
							width: 29%;
							margin-right: 37rpx;
							color: #a6a6a6;
						}

						&-right {
							width: 64%;
						}

						&-textareaLeft {
							color: #a6a6a6;
						}

						&-fireList {
							border-bottom: 2rpx solid #eee;
						}

						&-img {
							image {
								width: 100%;
								height: 140rpx;
							}
						}

						&-result {
							&-fraction {
								color: #adadad;
								margin: 34rpx 0 0;
							}

							&-text {
								margin-top: 38rpx;

								/deep/.u-input__textarea {
									font-size: 30rpx !important;
									color: #222222 !important;
									line-height: 1.3 !important;
									// padding: 0!important;
								}
							}
						}
					}
				}
			}
		}

		&-but {
			padding-bottom: env(safe-area-inset-bottom); // 针对iphone xr等系列的刘海底部屏幕做的适配
			position: fixed;
			bottom: 0;
			left: 0;
			width: 100%;
			background-color: #ffffff;

			/deep/.u-size-default {
				height: 100rpx !important;
				line-height: 100rpx !important;
			}
		}
	}

	.codeImg {
		width: 300rpx;
		height: 230rpx;
	}

	.butPrimary {
		font-size: 30rpx;
		text-align: center;
		border: 2rpx solid #3178ff;
		background: #3178FF;
		color: #fff;
		height: 100rpx;
		line-height: 100rpx;
		border-radius: 10rpx;
	}

	.textareaHeight {
		height: 250rpx;
	}
</style>